define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ip_tongji_data/index' + location.search,
                    add_url: 'ip_tongji_data/add',
                    edit_url: 'ip_tongji_data/edit',
                    del_url: 'ip_tongji_data/del',
                    multi_url: 'ip_tongji_data/multi',
                    import_url: 'ip_tongji_data/import',
                    table: 'ip_tongji_data',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                striped: true,
                columns: [
                    [
                        // {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'start_time', title: __('开始时间'),  addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('结束时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'total_num', title: __('IP生产总数'), operate:false},
                        {field: 'return_num', title: __('返回总数'),operate:false},
                        {field: 'expire_num', title: __('池内过期数'),operate:false},
                        {field: 'repeat60s_num', title: __('60s重复数'),operate:false},
                        {field: 'repeat60s_rate', title: __('60s重复率'),operate: false,
                            formatter:function(value,row){
                                return value+'%';
                            }},
                        {field: 'repeat24h_num', title: __('24H重复数'),operate:false},
                        {field: 'repeat24s_rate', title: __('24H重复率'),operate: false,
                        formatter:function(value,row){
                            return value+'%';
                        }},
                        {field: 'success_num', title: __('返回任务数量'),operate:false},
                        {field: 'create_repeat', title: __('创建任务重复数'),operate:false},
                        {
                            field: 'repeat60s_mark',
                            title: __('60s重复分布'),
                            operate: false,
                            // cellStyle: Controller.api.formatter.css,
                            formatter:function (value,row) {
                                return '重复分布&nbsp;&nbsp;&nbsp;<i class="fa fa-question-circle-o" onmouseenter="roleupdate(this)" onmouseleave="roleupdate2(this)" data-id="'+row.id+'" ></i>';
                            }
                        },
                        {
                            field: 'repreat24h_mark',
                            title: __('24H重复分布'),
                            operate: false,
                            // cellStyle: Controller.api.formatter.css,
                            formatter:function (value,row) {
                                return '重复分布&nbsp;&nbsp;&nbsp;<i class="fa fa-question-circle-o" onmouseenter="roleupdate24H(this)" onmouseleave="roleupdate3(this)" data-id="'+row.id+'" ></i>';
                            }
                        },
                        {field: 'created_at', title: __('统计时间'),operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});

function roleupdate(e){
    $(e).addClass('fa-question-circle');
    $(e).removeClass('fa-question-circle-o');
    var id = $(e).attr('data-id');
    var fa_this = $(e);

    var str2 = '代理商：重复代理商：数量</br>';
    $.post({
        async:true,
        url: "ip_tongji_data/get_repeat60s_json",
        data:{'id':id},
        success: function(res3){
            $.each(res3.data, function (k2, v2) {
                $.each(v2,function(k,m){
                    str2 += k2+' ：'+ k +' ：'+ m +'</br>';
                })

            });
            // console.log($(e));
            layer.tips(
                "<span style='color:black'>"+str2+"</span>",
                fa_this,
                {
                    area: ['300px', 'auto'],
                    // area: 'auto',
                    tips: [2, '#fff'],
                    time: 30000
                }
            );

        }
    });
}

function roleupdate2(e){
    $(e).addClass('fa-question-circle-o');
    $(e).removeClass('fa-question-circle');
    layer.closeAll();
}

function roleupdate24H(e){
    $(e).addClass('fa-question-circle');
    $(e).removeClass('fa-question-circle-o');
    var id = $(e).attr('data-id');
    var fa_this = $(e);

    var str2 = '代理商：重复代理商：数量</br>';
    $.post({
        async:true,
        url: "ip_tongji_data/get_repeat24h_json",
        data:{'id':id},
        success: function(res3){
            $.each(res3.data, function (k2, v2) {
                $.each(v2,function(k,m){
                    str2 += k2+' ：'+ k +' ：'+ m +'</br>';
                })

            });
            // console.log($(e));
            layer.tips(
                "<span style='color:black'>"+str2+"</span>",
                fa_this,
                {
                    area: ['300px', 'auto'],
                    // area: 'auto',
                    tips: [2, '#fff'],
                    time: 30000
                }
            );

        }
    });
}
function roleupdate3(e){
    $(e).addClass('fa-question-circle-o');
    $(e).removeClass('fa-question-circle');
    layer.closeAll();
}
